//
//  PPAlbumPictureView.m
//  pickpic
//
//  Created by Jinxiao on 9/29/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPAlbumPictureView.h"

@interface PPAlbumPictureView ()
@property (readwrite, nonatomic, strong) UILabel *label;
@property (readwrite, nonatomic, strong) UIView *view;
@end

@implementation PPAlbumPictureView

- (instancetype)init {
    self = [super init];

    _view = [[UIView alloc] init];
    _view.backgroundColor = [UIColor colorWithRGBHex:0x00 alpha:0.4];

    _label = [[UILabel alloc] init];
    _label.numberOfLines = 0;
    _label.textAlignment = NSTextAlignmentLeft;
    _label.lineBreakMode = NSLineBreakByWordWrapping;
    _label.font = [UIFont systemFontOfSize:13];
    _label.textColor = [UIColor whiteColor];
    [_view addSubview:_label];

    [self addSubview:_view];

    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];

    if(_desc.length == 0) {
        _view.hidden = YES;
    } else {
        _view.hidden = NO;
    }
    
    _view.width = self.width;

    _label.text = _desc;
    _label.width = self.width - 24;
    [_label sizeToFit];

    _view.height = _label.height + 12;
    _view.bottom = self.height;

    _label.frame = CGRectMake(12, 6, _view.width - 24, _view.height - 12);
}

- (void)setDesc:(NSString *)desc {
    _desc = desc;

    [self setNeedsLayout];
}

@end
